import queue.Queue;
import queue.QueueController;
import queue.QueueGUI;
import utils.Logger;
import coreSimulation.LoadBalancer;
import coreSimulation.MainFrame;
import coreSimulation.PassengerList;
import coreSimulation.MainFrameController;
import dropOffDesk.DeskController;
import dropOffDesk.DeskGUI;
import dropOffDesk.DeskPanel;
import dropOffDesk.DropOffDesk;

public class BaggageQueueSimulator {

	public static final int NUMBER_OF_DESKS = 3;
	// path to the Queue's CSV input file
	private static final String PASSENGER_INPUT_FILE = "Passengers.csv";
	private static final String BAGGAGE_INPUT_FILE = "Baggage.csv";

	public static void main(String[] args) {

		// clear the log files
		Logger.getLogger().clearLog(Logger.ERROR);
		Logger.getLogger().clearLog(Logger.EVENT);

		// create a new queue passing the path to the input file
		Queue queue = new Queue(PASSENGER_INPUT_FILE, BAGGAGE_INPUT_FILE);
		// create the queue GUI
		QueueGUI queueGUI = new QueueGUI(queue);
		// Create the controller for the queue's GUI
		new QueueController(queue, queueGUI);

		// create the passenger list
		PassengerList passengerList = new PassengerList();

		DropOffDesk[] desks = new DropOffDesk[NUMBER_OF_DESKS];
		DeskGUI deskGUI = new DeskGUI(NUMBER_OF_DESKS);
		MainFrame mainFrame = new MainFrame(queueGUI, deskGUI);
		mainFrame.setVisible(true);
		// create a controller to handle the window
		// close events for the two GUI components
		MainFrameController mainFrameController = new MainFrameController(
				queue, desks, passengerList);

		mainFrame.addWindowListener(mainFrameController);

		for (int i = 0; i < NUMBER_OF_DESKS; i++) {
			// create the drop-off-desk to process the queue
			DropOffDesk desk = new DropOffDesk(queue, passengerList);
			desks[i] = desk;
			// create the drop-off-desk's GUI
			DeskPanel deskPanel = new DeskPanel(desk);
			deskGUI.addDeskPanel(deskPanel, i + 1);

			// create the controller to handle the close button events
			new DeskController(deskPanel, desk);

		}

		// create LoadBalancer to manage opening/closing desks dependent upon
		// size of queue
		new LoadBalancer(desks, queue);

	}
}
